﻿@using DTcms.Common;
@{
    ViewBag.Title = "会员组管理";
}
<div class="pageheader">
    <div class="page-bar">
        <ul class="page-breadcrumb">
            <li><a href="javascript:;"><i class="iconfont icon-home1"></i> 首页</a> </li>
            <li><a href="javascript:;">会员管理</a> </li>
            <li><a href="javascript:;">会员组管理</a> </li>
        </ul>
    </div>
</div>
<div class="layui-fluid">
    <div class="layui-card layui-tab">
        <div class="layui-card-body table-tool-mini">
            <div class="layui-form toolbar">
                <div class="layui-form-item">
                    <div class="menu-list">
                        <div class="layui-inline">
                            <div class="layui-input-inline mr0">
                                <input id="txtKeywords" class="layui-input" type="text" placeholder="输入关键字" />
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn icon-btn layui-btn-normal layui-btn-sm" id="btnSearchAuth" data-type="btnSearch">
                                <i class="layui-icon">&#xe615;</i>搜索
                            </button>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-btn-group">
                            <a data-type="btnAdd" class="layui-btn icon-btn layui-btn-normal layui-btn-sm" href="../users/group_edit?action=@DTEnums.ActionEnum.Add"><i class="iconfont icon-close1"></i> 新增</a>
                            <a data-type="btnDelete" class="layui-btn icon-btn layui-btn-normal layui-btn-sm"><i class="iconfont icon-delete"></i> 删除</a>
                        </div>
                    </div>
                </div>
            </div>
            <table class="layui-table" lay-data="{page:true, id:'ltable'}" lay-filter="ltable">
                <thead>
                    <tr>
                        <th lay-data="{checkbox:true}"></th>
                        <th lay-data="{field:'title',templet:'#title',edit: 'text'}">组别名称</th>
                        <th lay-data="{field:'grade',edit: 'text'}">等级值</th>
                        <th lay-data="{field:'upgrade_exp', edit: 'text'}">升级经验</th>
                        <th lay-data="{field:'upgrade_price', edit: 'text'}">需冲值金额</th>
                        <th lay-data="{field:'amount', edit: 'text'}">初始金额</th>
                        <th lay-data="{field:'point', edit: 'text'}">初始积分</th>
                        <th lay-data="{field:'discount', edit: 'text'}">购物折扣</th>
                        <th lay-data="{field:'is_default',templet:'#is_default'}">注册组</th>
                        <th lay-data="{field:'is_lock',templet:'#switchTpl'}">状态</th>
                        <th lay-data="{templet: '#barDemo'}">操作</th>
                    </tr>
                </thead>
            </table>
        </div>
    </div>
</div>
<script type="text/html" id="is_default">
    {{d.is_default == 0 ?'<i class="simple text-success icon-close"></i>':'<i class="simple text-warning icon-check"></i>'}}
</script>
<script type="text/html" id="title">
    <a href="../users/group_edit?action=@DTEnums.ActionEnum.Edit&id={{d.id}}" class="layui-table-link">
        {{#  if(d.img_url != ''){ }}
        <img src="{{d.img_url}}" />
        {{#  } }}
        {{d.title}}
    </a>
</script>
<script type="text/html" id="barDemo">
    <a href="../users/group_edit?action=@DTEnums.ActionEnum.Edit&id={{d.id}}" class="layui-btn layui-btn-primary layui-btn-xs">修改</a>
</script>
<script type="text/html" id="switchTpl">
    <input type="checkbox" name="is_lock" value="{{d.id}}" lay-skin="switch" lay-text="启用|禁用" lay-filter="lock" {{ d.is_lock == 0 ? 'checked' : '' }}>
</script>
@section Scripts{
    <script type="text/javascript">
        layui.use(['table','cmswh'], function () {
            var table = layui.table, form = layui.form, cmswh = layui.cmswh, $ = layui.jquery;

            cmswh.dataBind('GroupList', getcond(), false);
            //监听单元格编辑
            table.on('edit(ltable)', function (obj) {
                var value = obj.value, data = obj.data, field = obj.field;
                cmswh.request("groupFiledSave?id=" + data.id + "&value=" + value + "&field=" + field, "POST");
            });
            //监听状态操作
            form.on('switch(lock)', function (obj) {
                cmswh.request("groupLock?id=" + this.value + "&is_lock=" + obj.elem.checked, "POST");
            });
            var active = {
                btnDelete: function () {
                    cmswh.batOperate('groupDelete', 'id');
                },
                btnSearch: function () {
                    cmswh.dataBind('GroupList', getcond(), false);
                }
            };
            $('.layui-inline .layui-btn').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });

            /*拼接条件返回postdata*/
            function getcond() {
                var keywords = $("#txtKeywords").val();
                var postdata = { keywords: keywords };
                return postdata;
            }
        });
    </script>
}